Select an operation to see a detailed explanation of its algorithm.
Algorithm: Find Minimum
The BST property guarantees that the minimum value is always the leftmost node in the tree.
- Start at the root node.
- Repeatedly follow the left child pointer.
- The last node reached (which has no left child) is the minimum.
Algorithm: Find Maximum
Symmetrically, the maximum value is always the rightmost node in the tree.
- Start at the root node.
- Repeatedly follow the right child pointer.
- The last node reached (which has no right child) is the maximum.
Algorithm: Find Successor
The successor of a node \(x\) is the node with the smallest key greater than \(x\)'s key. There are two cases:
- If node \(x\) has a right subtree: The successor is the minimum value in that right subtree.
- If node \(x\) has no right subtree: The successor is the lowest ancestor of \(x\) whose left child is also an ancestor of \(x\).
Algorithm: Find Predecessor
The predecessor of a node \(x\) is the node with the largest key smaller than \(x\)'s key. This is symmetric to finding the successor:
- If node \(x\) has a left subtree: The predecessor is the maximum value in that left subtree.
- If node \(x\) has no left subtree: The predecessor is the lowest ancestor of \(x\) whose right child is also an ancestor of \(x\).